{{ define "email.html" }}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>告警通知</title>
    <style>
        table { border-collapse: collapse; width: 100%; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
        .firing { color: #d9534f; }
        .resolved { color: #5cb85c; }
    </style>
</head>
<body>
    {{ if gt (len .Alerts.Firing) 0 }}
    <h2 class="firing">⚠️ 告警触发 ({{ len .Alerts.Firing }})</h2>
    <table>
        <tr><th>告警名称</th><th>容器/实例</th><th>描述</th></tr>
        {{ range .Alerts.Firing }}
        <tr>
            <td>{{ .Labels.alertname }}</td>
            <!-- <td>{{ .Labels.container_name }}{{ .Labels.instance }}{{ .Labels.name }}</td> -->
            <td>{{ .Labels.name }}</td>
            <td>{{ .Annotations.description }}</td>
        </tr>
        {{ end }}
    </table>
    {{ end }}

    {{ if gt (len .Alerts.Resolved) 0 }}
    <h2 class="resolved">✅ 告警恢复 ({{ len .Alerts.Resolved }})</h2>
    <table>
        <tr><th>告警名称</th><th>持续时间</th></tr>
        {{ range .Alerts.Resolved }}
        <tr>
            <td>{{ .Labels.alertname }}</td>
            <td>{{ ((.EndsAt.Sub .StartsAt).Seconds | printf "%.0f") }}秒</td>
        </tr>
        {{ end }}
    </table>
    {{ end }}
</body>
</html>
{{ end }}